#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;


//  Definition for a binary tree node.
  struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  };
 
class Solution {
public:
    int kthLargest(TreeNode* root, int k) {
        if(root==NULL){
            return 0;
        }
        int i = 0;
        int result;
        func(root,k,i,result);     
        return result;   
    }
    void func(TreeNode* root,int k,int& i,int& result){
        if(root==NULL){
            return ;
        }
        func(root->right,k,i,result);
        ++i;
        if(i==k){
            result = root->val;
            return;
        }
        func(root->left,k,i,result);
    }
};

int main(){
    Solution S;
    TreeNode* root = new TreeNode(3);
    root->left = new TreeNode(1);
    root->right = new TreeNode(4);
    root->left->right = new TreeNode(2);
    cout<<S.kthLargest(root,3)<<endl;
}